#include "dht.h"
#include "json.hpp"
#include <cstdint>
#include <fstream>
#include <string>

using json = nlohmann::json;

int main() {
  std::ifstream fin("./options.json");
  json options;
  fin >> options;
  auto url = options["mysqlx"]["url"];
  if (!url.is_string()) {
    std::cout << "url is not string" << std::endl;
    return 0;
  }
  auto port = options["mysqlx"]["port"];
  if (!port.is_number_integer()) {
    std::cout << "port is not number" << std::endl;
    return 0;
  }
  auto user = options["mysqlx"]["user"];
  if (!user.is_string()) {
    std::cout << "user is not string" << std::endl;
    return 0;
  }
  auto password = options["mysqlx"]["password"];
  if (!password.is_string()) {
    std::cout << "password is not string" << std::endl;
    return 0;
  }
  auto schemas = options["mysqlx"]["schema"];
  if (!schemas.is_string()) {
    std::cout << "schema is not string" << std::endl;
    return 0;
  }
  auto tables = options["mysqlx"]["table"];
  if (!tables.is_string()) {
    std::cout << "table is not string" << std::endl;
    return 0;
  }
  mysqlx::Session session(url.get<std::string>(), port.get<uint16_t>(), user.get<std::string>(),
                          password.get<std::string>());
  mysqlx::Schema schema = session.getSchema(schemas.get<std::string>());
  mysqlx::Table table = schema.getTable(tables.get<std::string>());
  cobt::DHTDigger digger(table);
  digger.listen(6881);
}
